<%@ page language="java" pageEncoding="UTF-8"
	contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	request.setAttribute("basePath", basePath);
%>
<!DOCTYPE>
<html>
<head>
<title>明细信息</title>
	<%@ include file="/resources/js/easyui/taglibs.jsp"%>
	<%@ include file="/resources/js/easyui/_easyui.jsp"%>
	<%@ include file="/resources/js/easyui/_message.jsp"%>
	<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
</head>

<body class="easyui-layout">
	<form id="editform">
		<table class="tableForm" style="width: 100%;">
			<tr>
				<th align="right" valign="top"><span class="redStart">*</span><label>用户组名称（中文）：</label></th>
				<td><input class="easyui-validatebox easyui-textbox"
					name="namecn" style="width:200px" value="${usergroup.textCN }"
					data-options="required:true,validType:'chinese'" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><span class="redStart">*</span><label>用户组名称（英文）：</label></th>
				<td><input class="easyui-validatebox easyui-textbox"
					name="sname" style="width:200px" value="${usergroup.textEN }"
					data-options="required:true,validType:'english'" /></td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>用户组说明：</label></th>
				<td><input class="easyui-textbox" name="remark"
					value="${usergroup.remark }" data-options="multiline:true"
					style="width:200px;height:60px;"></td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>用户组类型：</label></th>
				<td>
					<div style="float: left;">
						<input type="radio" name="userGroupType" value="1">系统管理 <input
							type="radio" name="userGroupType" value="2">商业用户 <input
							type="radio" name="userGroupType" value="3">商业子账户
					</div>

					<div id="GC_PatentUserGroup"
						style="float: left; margin-left: 4px;display: none;">
						<label>所属用户组：</label><select class="easyui-combobox"
							style="width:100px;" id="proleid"
							data-options="panelHeight:'auto'">
						</select>
					</div>
				</td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>默认自动分配：</label></th>
				<td><input type="radio" name="isdefault" value="1"
					<c:if test="${usergroup.isDefault == 1}">checked="checked"</c:if>>是
					<input type="radio" name="isdefault" value="0"
					<c:if test="${usergroup.isDefault == 0}">checked="checked"</c:if>>否
				</td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>是否可分配：</label></th>
				<td><input type="radio" name="isshare" value="1"
					<c:if test="${usergroup.isShare == 1}">checked="checked"</c:if>>是
					<input type="radio" name="isshare" value="0"
					<c:if test="${usergroup.isShare == 0}">checked="checked"</c:if>>否
				</td>
			</tr>

			<tr>
				<th align="right" valign="top"><label>用户组状态：</label></th>
				<td><input type="radio" name="state" value="1"
					<c:if test="${usergroup.useState == 1}">checked="checked"</c:if>>启用
					<input type="radio" name="state" value="2"
					<c:if test="${usergroup.useState == 2}">checked="checked"</c:if>>停用
				</td>
			</tr>
			<input type="hidden" name="roleid" value="${usergroup.userGroupid}" />
			<input type="hidden" name="proleid" value="${usergroup.parentid}" />

		</table>

	</form>

	<script type="application/javascript">

	var parentid = ${usergroup.parentid}
	$(function() {
		var defaultState = $("input[name='isdefault']:checked").val();
		if(parentid == 1 && defaultState == 0){
			$("input[type='radio'][name='userGroupType'][value='1']").attr("checked",'checked'); 
		}else if(parentid == 1 && defaultState == 1){
			$("input[type='radio'][name='userGroupType'][value='2']").attr("checked",'checked'); 
		}else{
			$("input[type='radio'][name='userGroupType'][value='3']").attr("checked",'checked');
			getParentUserGroup(parentid);
			$("select option[value='"+parentid+"']").attr("selected", 'selected');  
		}
	});
	
	function getParentUserGroup(parentid){
		$.ajax({
			url:'${basePath}web/userGroup/parentUserGroup.json',
			type : 'GET',
			dataType:'json',
			async : false,
			success: function (data) {
				$("#proleid").combobox({ valueField: "userGroupid",  textField: "textCN", data: data ,onLoadSuccess : function() {			
					$("#proleid").combobox("setValue",parentid);
				} });
				$("#GC_PatentUserGroup").show();
			},error:function(response){
				ViewHelper.func.ajaxErrorMessage(response);
			}
		});
	}
	
	$("input[type='radio'][name='userGroupType']").click(function(){
		if($(this).val() == '3'){
			getParentUserGroup(parentid);
		}else{
			$("#proleid").combobox("setValue",1);
			$("#GC_PatentUserGroup").hide();
		}
		
	});
	
	
    function edit(){
        if($("#editform").form('validate')){
        	$("input[type='hidden'][name='proleid']").val($("#proleid").combobox("getValue"));
            $.ajax({
                url:'${basePath}web/userGroup/editUserGroup',
                type : 'POST',
                data : $("#editform").serialize(),
                async : false, //默认为true 异步
                traditional:true,
                error: function (response) {
                    ViewHelper.func.ajaxErrorMessage(response);
                },
                success: function (ret) {
                    if(ret.result) {
                        $.messager.alert('提示信息！',ret.info,'info');
                        parent.view.closeEditWin(1);
                        $("#editform").form('clear');
                    }else{
                        $.messager.alert('提示','保存失败!','error');
                    }
                }
            });
        }
    }
	
	$.extend($.fn.validatebox.defaults.rules, {
		chinese: {
			 validator : function(value) {
                 return /^[\u0391-\uFFE5]+$/.test(value);
             },
             message : '请输入正确的中文名称'
		},
		english:{
			validator: function(value){
				return /^[a-zA-Z]+$/.test(value);
			},
			message: '请输入正确的英文名称'
		}
		
	});

	</script>
</body>
</html>
